package com.weilive.api.gate.json.handler;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.weilive.api.gate.json.protocol.CSA_DiscoverView;
import com.weilive.api.gate.json.protocol.CSQ_DiscoverView;
import com.weilive.api.service.DiscoverSystem;
import com.weilive.core.protocol.json.JsonRequest;
import com.weilive.core.protocol.json.JsonRequestHandler;
import com.weilive.core.protocol.json.JsonResponse;

@Service
public class CSQ_DiscoverView_JsonHandler extends JsonRequestHandler {

	@Autowired
	private DiscoverSystem discoverSystem;

	public Class<?> getRequestType() {
		return CSQ_DiscoverView.class;
	}

	public Class<?> getResponseType() {
		return CSA_DiscoverView.class;
	}

	public JsonResponse handleRequest(JsonRequest request) throws Exception {
		CSQ_DiscoverView params = (CSQ_DiscoverView) request.getData();
		CSA_DiscoverView response = new CSA_DiscoverView();
		// 0:游客
		long userId = params.getUserId() == null ? 0L : params.getUserId();

		if (params.getVjTypeId() != null && params.getPage() != null) {
			// 根据sessionId获取userId 更多
			response = discoverSystem.getMoveDiscoverMsg(userId, params.getVjTypeId(), params.getPage());
		} else {
			// 根据sessionId获取userId
			response = discoverSystem.getDiscoverMsg(userId);
		}

		return JsonResponse.create(response);
	}

}
